package com.organization.model;

import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.Length;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import javax.validation.constraints.Pattern;
import java.sql.Timestamp;

/**
 * Created with IntelliJ IDEA.
 * User: inester
 * Date: 09.07.12
 * Time: 12:04
 * To change this template use File | Settings | File Templates.
 */
@Entity
public class Employee {
    private int id;
    private Project project;
    private String lastName;
    private String firstName;
    private Timestamp hireDate;
    private String workPosition;
    private String addressApartment;
    private String addressHouse;
    private String addressStreetCity;
    private String email;
    private String extensionPhone;
    private String homePhone;
    private String mobilePhone;
    private Timestamp birthDate;
    private String gender;

    @Column(name = "ID")
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "PROJECT_ID", nullable = false)
    public Project getProject() {
        return project;
    }

    public void setProject(Project project) {
        this.project = project;
    }

    @Column(name = "ADDRESS_APARTMENT")
    @Basic
    public String getAddressApartment() {
        return addressApartment;
    }

    public void setAddressApartment(String addressApartment) {
        this.addressApartment = addressApartment;
    }

    @Column(name = "ADDRESS_HOUSE")
    @Basic
    public String getAddressHouse() {
        return addressHouse;
    }

    public void setAddressHouse(String addressHouse) {
        this.addressHouse = addressHouse;
    }

    @Column(name = "ADDRESS_STREET_CITY")
    @Basic
    @Length(max=32)
    public String getAddressStreetCity() {
        return addressStreetCity;
    }

    public void setAddressStreetCity(String addressStreetCity) {
        this.addressStreetCity = addressStreetCity;
    }

    @Column(name = "BIRTH_DATE")
    @Basic
    public Timestamp getBirthDate() {
        return birthDate;
    }

    public void setBirthDate(Timestamp birthDate) {
        this.birthDate = birthDate;
    }

    @Column(name = "EMAIL")
    @Basic
    @Email
    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @Column(name = "EXTENSION_PHONE")
    @Basic
    @Pattern(regexp = "[0-9]{4,}|")
    public String getExtensionPhone() {
        return extensionPhone;
    }

    public void setExtensionPhone(String extensionPhone) {
        this.extensionPhone = extensionPhone;
    }

    @Column(name = "FIRST_NAME")
    @Basic
    @NotNull
    @Length(min=2, max=255)
    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    @Column(name = "GENDER")
    @Basic
    @Pattern(regexp = "M|F|", message = "Available values is 'M' and 'F'")
    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    @Column(name = "HIRE_DATE")
    @Basic
    public Timestamp getHireDate() {
        return hireDate;
    }

    public void setHireDate(Timestamp hireDate) {
        this.hireDate = hireDate;
    }

    @Column(name = "HOME_PHONE")
    @Basic
    @Pattern(regexp = "[0-9]{4,}|")
    public String getHomePhone() {
        return homePhone;
    }

    public void setHomePhone(String homePhone) {
        this.homePhone = homePhone;
    }

    @Column(name = "LAST_NAME")
    @Basic
    @NotNull
    @Length(min=2, max=255)
    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    @Column(name = "MOBILE_PHONE")
    @Basic
    @Pattern(regexp = "^[/+]{0,1}[0-9]{11}|$")
    public String getMobilePhone() {
        return mobilePhone;
    }

    public void setMobilePhone(String mobilePhone) {
        this.mobilePhone = mobilePhone;
    }

    @Column(name = "WORK_POSITION")
    @Basic
    public String getWorkPosition() {
        return workPosition;
    }

    public void setWorkPosition(String workPosition) {
        this.workPosition = workPosition;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Employee employee = (Employee) o;

        if (id != employee.id) return false;
        if (project.getId() != employee.project.getId()) return false;
        if (addressApartment != null ? !addressApartment.equals(employee.addressApartment) : employee.addressApartment != null)
            return false;
        if (addressHouse != null ? !addressHouse.equals(employee.addressHouse) : employee.addressHouse != null)
            return false;
        if (addressStreetCity != null ? !addressStreetCity.equals(employee.addressStreetCity) : employee.addressStreetCity != null)
            return false;
        if (birthDate != null ? !birthDate.equals(employee.birthDate) : employee.birthDate != null) return false;
        if (email != null ? !email.equals(employee.email) : employee.email != null) return false;
        if (extensionPhone != null ? !extensionPhone.equals(employee.extensionPhone) : employee.extensionPhone != null)
            return false;
        if (firstName != null ? !firstName.equals(employee.firstName) : employee.firstName != null) return false;
        if (gender != null ? !gender.equals(employee.gender) : employee.gender != null) return false;
        if (hireDate != null ? !hireDate.equals(employee.hireDate) : employee.hireDate != null) return false;
        if (homePhone != null ? !homePhone.equals(employee.homePhone) : employee.homePhone != null) return false;
        if (lastName != null ? !lastName.equals(employee.lastName) : employee.lastName != null) return false;
        if (mobilePhone != null ? !mobilePhone.equals(employee.mobilePhone) : employee.mobilePhone != null)
            return false;
        if (workPosition != null ? !workPosition.equals(employee.workPosition) : employee.workPosition != null)
            return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = id;
        result = 31 * result + project.getId();
        result = 31 * result + (addressApartment != null ? addressApartment.hashCode() : 0);
        result = 31 * result + (addressHouse != null ? addressHouse.hashCode() : 0);
        result = 31 * result + (addressStreetCity != null ? addressStreetCity.hashCode() : 0);
        result = 31 * result + (birthDate != null ? birthDate.hashCode() : 0);
        result = 31 * result + (email != null ? email.hashCode() : 0);
        result = 31 * result + (extensionPhone != null ? extensionPhone.hashCode() : 0);
        result = 31 * result + (firstName != null ? firstName.hashCode() : 0);
        result = 31 * result + (gender != null ? gender.hashCode() : 0);
        result = 31 * result + (hireDate != null ? hireDate.hashCode() : 0);
        result = 31 * result + (homePhone != null ? homePhone.hashCode() : 0);
        result = 31 * result + (lastName != null ? lastName.hashCode() : 0);
        result = 31 * result + (mobilePhone != null ? mobilePhone.hashCode() : 0);
        result = 31 * result + (workPosition != null ? workPosition.hashCode() : 0);
        return result;
    }

    @Override
    public String toString(){
        return lastName+" "+firstName;
    }

}
